﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows;
using TorchView.GameContent.Data;
using System.Xml.Linq;
using TorchView.Imaging;
using System.Diagnostics;

namespace TorchView.GameContent
{
  /// <summary>
  /// Class used to get item icons
  /// </summary>
  public static class Icons
  {
    private static Dictionary<string, ImageSet.Image> _Images = new Dictionary<string, ImageSet.Image>();

    static Icons()
    {
      LoadImages();
    }

    /// <summary>
    /// Get the image by the specified icon name
    /// </summary>
    /// <param name="iconName">Name of the image to retrieve</param>
    /// <returns>The image if one is found, null if one is not found</returns>
    public static BitmapSource GetImage(string iconName)
    {
      ImageSet.Image image;
      if (_Images.TryGetValue(iconName, out image))
        return image.GetBitmapSource();
      return null;
    }

    private static void LoadImages()
    {
      var imageSets = PakReader.GetFiles("media/UI/itemicons/", "*.imageset", System.IO.SearchOption.AllDirectories);
      foreach (var set in ImageSet.LoadImages(imageSets))
        foreach (var image in set)
          _Images[image.Key] = image.Value;
    }
  }
}
